﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using game_for_test_helper.src.graphics;

namespace game_for_test_helper.src.modelcontrol
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class HumanControl : Microsoft.Xna.Framework.DrawableGameComponent
    {
        Human human;
        public HumanControl(Game game)
            : base(game)
        {


        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            WalkOrRun = true;
            base.Initialize();
        }
        protected override void LoadContent()
        {
            human = new Human();
            SimpleCamera.SetFollowObject(human);
            base.LoadContent();
        }
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        private bool WalkOrRun;
        public override void Update(GameTime gameTime)
        {
            Vector2 LeftPad = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left;
            Vector2 RightPad = GamePad.GetState(PlayerIndex.One).ThumbSticks.Right;

            if (LeftPad.X != 0 || LeftPad.Y != 0)
            {
                if (WalkOrRun)
                    human.WalkDirection(LeftPad.X, LeftPad.Y);
                else
                    human.WalkFastDirection(LeftPad.X, LeftPad.Y);
            }
            else if (LeftPad.X != 0 || LeftPad.Y < 0)
            {
            }
            else
            {

            }
            human.PositionY += RightPad.X * 10;

            if (GamePad.GetState(PlayerIndex.One).DPad.Left == ButtonState.Pressed)
                human.TurnLeft();
            if (GamePad.GetState(PlayerIndex.One).DPad.Right == ButtonState.Pressed)
                human.TurnRight();

            if (GamePad.GetState(PlayerIndex.One).Buttons.LeftShoulder == ButtonState.Released)
                if (LeftShoulder == ButtonState.Pressed)
                {
                    WalkOrRun = !WalkOrRun;
                    LeftShoulder = ButtonState.Released;
                }

            if (GamePad.GetState(PlayerIndex.One).Buttons.LeftShoulder == ButtonState.Pressed)
            {
                LeftShoulder = ButtonState.Pressed;
            }

            human.Update(gameTime);
            base.Update(gameTime);
        }
        private ButtonState LeftShoulder;
        public override void Draw(GameTime gameTime)
        {
            human.Draw(gameTime);
            base.Draw(gameTime);
        }
    }
}